package com.rd.student.jiaji.class4.suyan.zrrd.Exam;

import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class StudentTest {
    public static void main(String[] args) throws Exception{
        File file=new File("Student.txt");
        file.createNewFile();
test(file);
    }
    public static void test(File file) throws Exception{
        Scanner scanner=new Scanner(System.in);
        System.out.println();
        List list=new ArrayList();
        System.out.println("请录入学生信息");
        while (true){
            System.out.println("1：继续录入，0：结束录入");
            int select=scanner.nextInt();
            if (select==0){
                break;
            }
            System.out.println("请输入学生姓名");
            String name=scanner.next();
            System.out.println("请输入学生语文成绩");
            int chinasum=scanner.nextInt();
            System.out.println("请输入学生数学成绩");
            int mathsum=scanner.nextInt();
            int sum=mathsum+chinasum;
            Student s=new Student(name,chinasum,mathsum,sum);
            list.add(s);
        }
        System.out.println("姓名 语文成绩 数学成绩 总分");

        String arr="";
        for (Object obj:list){
            arr=arr+"\n"+""+obj;
            System.out.println(arr);
        }
//        OutputStream os=new FileOutputStream(file);
////        byte[] arr4=arr3.getBytes();
//        byte[] arr1=arr.getBytes();
////        os.write(arr4);
//        os.write(arr1);
////        os.close();
//        os.close();
//        Writer writer=new FileWriter(file);
//        writer.write(arr);
//        writer.close();
//        Reader reader=new FileReader(file);
        String arr3="姓名 语文成绩 数学成绩 总分";
        String arr4=arr3+"\n"+arr;
        byte[] arr1=arr4.getBytes();
//
        BufferedOutputStream bufferedOutputStream=new BufferedOutputStream(new FileOutputStream(file));
        bufferedOutputStream.write(arr1);
        bufferedOutputStream.close();


    }
}
